<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新用户注册</title>
</head>
<link rel="icon" href="data:;base64,=">
<link rel="stylesheet" href="/static/layui/layui/css/layui.css">
<link rel="stylesheet" href="/static/css/register.css"  />
<body>
<div class="wrapper register">
    <table>
        <tr>
            <td>
                <div class="register_head">
                    <p class="zh"><br/>快递之家管理平台 <span class="bb" style="position:initial;">Ver 1.0</span></p>
                    <p class="en">EXPRESS HOME MANAGEMENT PLATFORM</p>
                </div>
            </td>
            <td class="right">
                <div class="register_box">
                    <p class="zczh">注册平台账号</p>
                    <form class="layui-form" action="/kh/register">
                        <div class="text_input user_input">
                            <i class="icon"></i>
                            <input class="cookie" type="hidden" name="_csrf">
                            <input id="username" name="kno" placeholder="请输入登录账号" type="text" required lay-verify="required|username">
                        </div>
                        <div class="text_input pwd_input">
                            <i class="icon"></i>
                            <input id="kn" name="kn" placeholder="请输入您的用户名" class=""  type="text" required lay-verify="required|confirmPass">
                        </div>
                        <div class="text_input pwd_input">
                            <i class="icon"></i>
                            <input id="password" name="kpw"  placeholder="请输入您的密码" class=""  type="password" required lay-verify="required">
                        </div>
                        <div class="text_input item_input">
                            <i class="icon"></i>
                            <input id="phone" name="ktelephone" placeholder="请输入您的手机号码" type="text" required lay-verify="required|phone|number">
                        </div>
                        <div class="text_input item_input">
                            已有账号？现在去 <a href="/login/">登录</a>
                        </div>
                        <div class="text_input item_input">
                            <input id="register-button" accesskey="l" value="注册" tabindex="4"  type="submit" lay-filter="zhuce"/>
                        </div>
                    </form>
                </div>
            </td>
        </tr>
    </table>
</div>
</body>
<script src="/static/jquery/jquery-3.4.0.js"></script>
<script src="/static/layui/layui/layui.all.js"></script>
<script>
    layui.use(['jquery','element','form','table','layer','laydate'], function(){
        var $ = layui.jquery;
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;

        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
            },
            confirmPass:function(value){
                if($("input[name='password']").val() !== value)
                    return '两次密码输入不一致！';
            }
        });

        form.on("submit(zhuce)", function (data) {
            var layer = layui.layer;
            // layer.msg(JSON.stringify(data.field));
            var username1 = $("#username").val();
            var password1 = $("#password").val();
            var kn = $("#kn").val();
            var phone1 = $("#phone").val();
            //监听提交
            /*form.on('submit(zhuce)', function(data){
                layer.msg(JSON.stringify(data.field));
                return false;
            });*/
            $.ajax({
                url:"/kh/save",
                type:"POST",
                datatype:"json",
                data:{"kno": username1,"kn":kn, "kpw": password1, "ktelephone": phone1},
                success:function (res) {
                    if (res.code==0){
                        window.location.href="/toIndex"
                    }
                    alert(res);
                    layer.msg(res.data);
                }
            })
            // return false;
        })
    });

    // function check() {
    //     var layer = layui.layer;
    //     if ($("#username").val().length==0){
    //         layer.msg("请输入用户名！")
    //         return false;
    //     }
    //     if ($("#password").val().length==0){
    //         layer.msg("请输入密码！")
    //         return false;
    //     }
    //     var pd1 = $("#password").val();
    //     var pd2 = $("#password_again").val();
    //     if (pd1!=pd2){
    //         layer.msg("两次密码不一致！")
    //         return false;
    //     }
    //     if ($("#phone").val().length==0){
    //         layer.msg("请输入电话号码！")
    //         return false;
    //     }
    //     return true;
    // }

    // $("#register-button").on("click", function () {
    //     var layer = layui.layer;
    //     $.ajax({
    //         url:"/registerinfo/register",
    //         type:"POSY",
    //         datatype:"json",
    //         data:{"username": username1, "password": password1, "password_again": password2, "phone": phone1},
    //         success:function (res) {
    //             layer.msg("注册成功");
    //         }
    //     })
    // });
</script>
</html>